/* Turska Framework/UI library (Turs2)
 * Copyright 2003-2010 Jetro Lauha
 * All rights reserved.
 * Web: http://iki.fi/jetro/turska/
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of EITHER:
 *   (1) The GNU Lesser General Public License as published by the Free
 *       Software Foundation; either version 2.1 of the License, or (at
 *       your option) any later version. The text of the GNU Lesser
 *       General Public License is included with this library in the
 *       file LICENSE-LGPL.txt.
 *   (2) The BSD-style license that is included with this library in
 *       the file LICENSE-BSD.txt.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
 * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
 *
 * $Id: T2GraphicsSDLOpenGL.h 183 2010-12-28 15:27:37Z jlauha $
 * $Revision: 183 $
 */

#ifndef T2GRAPHICSSDLOPENGL_H_INCLUDED
#define T2GRAPHICSSDLOPENGL_H_INCLUDED


#include "T2GraphicsOpenGL.h"


struct SDL_Surface;
struct SDL_RWops;


namespace turska
{
    //! Implementation of Turska Graphics which uses SDL and OpenGL.
    /*! This implementation requires the SDL and SDL_image libraries.
     * \TODO support IF_LOAD_16BIT, IF_LOAD_DISCARD_ALPHA
     */
    class GraphicsSDLOpenGL : public turska::GraphicsOpenGL
    {
    public:
    
        GraphicsSDLOpenGL(I32 windowWidth, I32 windowHeight) :
            GraphicsOpenGL(windowWidth, windowHeight) {}
        virtual ~GraphicsSDLOpenGL() {}
    
        // From turska::Graphics:
    
        virtual Image * loadImage(const C8 *fileName,
                                  UI32 flags = G_USE_DEFAULT_FLAGS);
    
        // GraphicsSDLOpenGL additions:
    
        //! Loads and constructs an Image from given SDL_RWops object.
        /*!
         * \param source data object to load image from.
         * \param deleteSource true if source should be deleted after loading
         *                     the image or false otherwise.
         * \param flags image flags to use when loading image.
         *              \sa turska::IMAGE_FLAG
         * \return image object if successful, or 0 if unsuccessful.
         */
        virtual Image * loadImage(SDL_RWops *source, bool deleteSource,
                                  UI32 flags = G_USE_DEFAULT_FLAGS);
    
        //! Loads a SDL_Surface from given file name.
        /*!
         * \param fileName file name of image to load.
         * \return surface object if successful, or 0 if unsuccessful.
         */
        virtual SDL_Surface * loadSurface(const C8 *fileName);
    
        //! Loads a SDL_Surface from given SDL_RWops object.
        /*!
         * \param source data object to load image from.
         * \param deleteSource true if source should be deleted after loading
         *                     the image or false otherwise.
         * \return surface object if successful, or 0 if unsuccessful.
         */
        virtual SDL_Surface * loadSurface(SDL_RWops *source, bool deleteSource);
    
        //! Constructs an Image from given SDL_Surface.
        /*!
         * \param surface surface to create Image from.
         * \param flags image flags to use when constructing image.
         *              \sa turska::IMAGE_FLAG
         * \param sourceRect optional source rectangle to crop from the surface,
         *                   or 0 to use the whole surface.
         */
        virtual Image * createImage(SDL_Surface *surface, UI32 flags,
                                    PixelRectangle *sourceRect = 0);
    
        //! Creates an OpenGL texture from given SDL_Surface.
        /*!
         * \param oTexture resulting OpenGL texture name, when successful.
         * \param oUV resulting top-left and bottom-right U,V coordinates
         *            in texture (4 floats), when successful.
         * \param surface surface to create texture from.
         * \param flags image flags to use when constructing image.
         *              \sa turska::IMAGE_FLAG
         * \param sourceRect optional source rectangle to crop from the surface,
         *                   or 0 to use the whole surface.
         * \return true if successful, or false if unsuccessful.
         */
        virtual bool createTexture(UI32 &oTexture, F32 *oUV,
                                   SDL_Surface *surface, UI32 flags,
                                   PixelRectangle *sourceRect = 0);
    
    protected:

    }; // GraphicsSDLOpenGL
} // namespace turska


#endif // !T2GRAPHICSSDLOPENGL_H_INCLUDED
